package cn.iocoder.yudao.module.promotion.redpacket.api;

import cn.iocoder.yudao.module.api.promotion.redpacket.RedPacketApi;
import cn.iocoder.yudao.module.api.promotion.redpacket.vo.RedPacketAmountVO;
import cn.iocoder.yudao.module.api.promotion.redpacket.vo.RedPacketConfigVO;
import cn.iocoder.yudao.module.api.promotion.redpacket.vo.RedPacketUsageVO;
import cn.iocoder.yudao.module.promotion.redpacket.convert.RedPacketConfigConvert;
import cn.iocoder.yudao.module.promotion.redpacket.pojo.po.RedPacketConfig;
import cn.iocoder.yudao.module.promotion.redpacket.service.app.AppRedPacketRecordService;
import cn.iocoder.yudao.module.promotion.redpacket.service.core.CoreRedPacketConfigService;
import cn.iocoder.yudao.module.promotion.redpacket.service.core.CoreRedPacketRecordService;
import jakarta.annotation.Nonnull;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/06/28
 */
@Slf4j
@Validated
@Service
public class RedPacketApiImpl implements RedPacketApi {
    @Resource
    private CoreRedPacketConfigService coreRedPacketConfigService;
    @Resource
    private CoreRedPacketRecordService coreRedPacketRecordService;
    @Resource
    private AppRedPacketRecordService appRedPacketRecordService;

    @Nonnull
    @Override
    public RedPacketConfigVO getRedPacketConfig(Long shopId) {
        RedPacketConfig config = coreRedPacketConfigService.getOrCreate(shopId);
        return RedPacketConfigConvert.INSTANCE.toViewObject(config);
    }

    @Override
    public RedPacketAmountVO getRedPacketAmount(Long userId, Long shopId) {
        return coreRedPacketRecordService.getRedPacketAmount(userId, shopId);
    }

    @Nonnull
    @Override
    public RedPacketUsageVO getMatchedRedPacket(Long userId, Long shopId, Integer orderAmount) {
        return appRedPacketRecordService.getMatchedRedPacket(userId, shopId, orderAmount);
    }

}
